var http = require('http');
var fs = require('fs');
var path = require('path');
http.createServer((req, res) => {
        res.writeHead(200, {
            'Content-Type': "text/html"
        })
        var filePath = path.join(__dirname, "图片1.png");
        var data = fs.readFileSync(filePath);
        var imgBase64 = data.toString('base64');
        res.write("<!DOCTYPE html><html>" + "<head></head><body>" +
            "<img src='data:image/png;base64," + imgBase64 + "'/>" +
            "</body></html>");
        res.end('hello world');
    }

).listen(8080);
console.log('server is listening on 8080');























// var http = require('http');
// var fs = require('fs');
// var path = require('path');
// http.createServer(function (req, res) {
//     res.writeHead(200, {
//         "Content-Type": "text/html"
//     });
//     var filePath = path.join(__dirname, "0.jpg");
//     var imgBuf = fs.readFileSync(filePath);
//     console.log(imgBuf);
//     var imgBase64 = imgBuf.toString("base64");
//     res.write("<!DOCTYPE html><html>" + "<head></head><body style='background:red;'>" +
//         "<img src='data:image/jpg;base64," + imgBase64 + "'/>" + "</body>" + "</html>")
//     res.end("hello world");
// }).listen(8081);
// console.log("server listening on port 8081");